home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / dict / _int_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.9 KB  |  98 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _int_set.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <LEDA/int_set.h>
  16.  
  17. typedef unsigned long  word;
  18.  
  19. int_set::int_set(int n)
  20. { size = n; 
  21.   low = 0;
  22.   register int i = 1+size/32;
  23.   if ((V=new word[i]) == 0) error_handler(1,"int_set: out of memory"); 
  24.   while (i--) V[i]=0;
  25.  } 
  26.  
  27. int_set::int_set(int a, int b)
  28. { size = b-a+1; 
  29.   low = a;
  30.   register int i = 1+size/32;
  31.   if ((V=new word[i]) == 0) error_handler(1,"int_set: out of memory"); 
  32.   while (i--) V[i]=0;
  33.  } 
  34.  
  35. int_set::int_set(const int_set& b)
  36. { size = b.size;
  37.   low  = b.low;
  38.   register int n = 1+size/32;
  39.   V = new word[n];
  40.   while (n--) V[n] = b.V[n];
  41. }
  42.  
  43. int_set& int_set::operator=(const int_set& b)
  44. { if (this == &b) return *this;
  45.   delete V;
  46.   size = b.size;
  47.   low  = b.low;
  48.   register int n = 1+size/32;
  49.   V = new word[n];
  50.   while (n--) V[n] = b.V[n];
  51.   return *this;
  52. }
  53.  
  54. void int_set::clear()
  55. { register int i = 1+size/32;
  56.   while (i--) V[i]=0;
  57.  }
  58.   
  59.  
  60. int_set& int_set::join(const int_set& b) 
  61. { word* stop = V+size/32 +1;
  62.   word* p;
  63.   word* q;
  64.   for(p = V, q = b.V; p<stop; p++, q++) *p |= *q;
  65.   return *this;
  66.  }
  67.  
  68. int_set& int_set::intersect(const int_set& b) 
  69. { word* stop = V+size/32 +1;
  70.   word* p;
  71.   word* q;
  72.   for(p = V, q = b.V; p<stop; p++, q++) *p &= *q;
  73.   return *this;
  74.  }
  75.  
  76. int_set& int_set::complement() 
  77. { word* stop = V+size/32 +1;
  78.   for(word* p = V; p<stop; p++) *p = ~(*p);
  79.   return *this;
  80.  }
  81.  
  82. int_set  int_set::operator|(const int_set& b) 
  83. { int_set res(*this); 
  84.   return res.join(b); 
  85.  }
  86.  
  87. int_set  int_set::operator&(const int_set& b) 
  88. { int_set res(*this); 
  89.   return res.intersect(b); 
  90.  }
  91.  
  92. int_set  int_set::operator~()   
  93. { int_set res(*this); 
  94.   return res.complement(); 
  95.  }
  96.  
  97.